﻿<%--
 *  File:    VisitPlanEditSummary.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  String strModuleName = "SFE";
  String privilegeCode = "H0255,H0256,H0259";
  	String contextPath = request.getContextPath();
%>

<%@ include file="/inc/Security.inc" %>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>VisitPlanEditSummary</title>
<PageFlow:CheckPageFlow pageName="p_visitplaneditsummary"/>
	<style>
.current_day
{
			background-color:#fed99d;
}
.disabled_day
{
	background-color:#F3F3F3;
}
	</style>	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script>
	function page_selectedday(nyear,nmonth,nweek,nday,ndate)
	{  
		/*if(Number(nday)==7){
		nday=1;
		nweek=Number(nweek)+1;
		}else{
		nday=Number(nday)+1;
		}*/
		page_selectedweek(nyear,nmonth,nweek);
		var strUrl="VisitPlanEditOneDay.jsp?ishistory=<custom:write property="ishistory"/>&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>";
		strUrl=strUrl+"&year=<custom:write property="year"/>&monthofyear=<custom:write property="monthofyear"/>&weekofmonth="+nweek+"&dayofweek="+nday+"&dayofmonth="+ndate;
		strUrl=strUrl+"&<%= OvalTools.randomURL() %>";
		var vwidth=(screen.availWidth - 10);
		var vheight=(screen.availHeight-50);
		var status="width="+vwidth +",height="+vheight +",resizable=yes,toolbar=no";
     if(popwindow!=null)
      popwindow.close();
      popwindow=window.open(strUrl, "newwindow", status,true);
	}
	
	function page_selectedweek(nyear,nmonth,nweek)
	{
		radiotrue("rdo_week"+nweek);
		var cform = document.cform;
		cform.week.value=nweek;
	}
	
	function page_addfromtemplet()
	{
		var now = new Date();   
		var month = now.getMonth(), year = now.getFullYear(), w = now.getDay(), d = now.getDate(); 
		var week = Math.ceil( (d + 6 - w) / 7 ); 
		var cform = document.cform;
		var nyear=cform.year.value;
		var nmonth=cform.monthofyear.value;
		nmonth=nmonth-1;
		var nweek=cform.week.value;
	//	if(year<=nyear&&month<=nmonth&&week<=nweek)
		if(isEmpty(nweek) || nweek == -1 )
		{
			alert("<%=message.getMessageDesc("PLEASE_SELECT")%>");
			 return;
		}
		if(year<=nyear)
		{
			if(year==nyear&&month==nmonth&&week==nweek)
			{
				var strUrl="VisitPlanTempletSelectFrm.jsp?ishistory=<custom:write property="ishistory"/>&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>";
				strUrl=strUrl+"&year=<custom:write property="year"/>&monthofyear=<custom:write property="monthofyear"/>&weekofmonth="+nweek;
				strUrl=strUrl+"&<%= OvalTools.randomURL() %>&dayofweek="+w;
				var status="height=500, width=1000,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
				}else if(year==nyear&&month>nmonth){
					alert("<%=message.getMessageDesc("OVER_TIME")%>");
					return;
				}else if(year==nyear&&month==nmonth&&week>nweek)
				{
					alert("<%=message.getMessageDesc("OVER_TIME")%>");
					return;
				}else{
					var strUrl="VisitPlanTempletSelectFrm.jsp?ishistory=<custom:write property="ishistory"/>&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>";
					strUrl=strUrl+"&year=<custom:write property="year"/>&monthofyear=<custom:write property="monthofyear"/>&weekofmonth="+nweek;
					strUrl=strUrl+"&<%= OvalTools.randomURL() %>";
					var status="height=500, width=1000,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
				}
					if(popwindow!=null)
					popwindow.close();
					popwindow=window.open(strUrl, "newwindow", status);
			}else{
				alert("<%=message.getMessageDesc("OVER_TIME")%>");
				return;
			}
	}

	function page_editweek()
	{
		var cform = document.cform;
		var nweek=cform.week.value;
		if(isEmpty(nweek) || nweek == -1 )
		{
			alert("<%=message.getMessageDesc("PLEASE_SELECT")%>");
			 return;
		}
	
		var strUrl="VisitPlanEditDetail.jsp?ishistory=<custom:write property="ishistory"/>&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>";
		strUrl=strUrl+"&year=<custom:write property="year"/>&monthofyear=<custom:write property="monthofyear"/>&weekofmonth="+nweek;
		strUrl=strUrl+"&<%= OvalTools.randomURL() %>";
		 var status="height=500, width=1000,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no";
      if(popwindow!=null)
      popwindow.close();
      popwindow=window.open(strUrl, "newwindow", status);
	}
	function page_back()
	{
		parent.location.href="VisitPlanSummary.jsp?ishistory=<custom:write property="ishistory"/>&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>&<%= OvalTools.randomURL() %>";
	}
	function refreshWindow()
	{
		 if(popwindow!=null)
      popwindow.close();
		parent.topFrame.page_selectedmonth(' <custom:write property="year"/>','<custom:write property="monthofyear"/>');
	}
function page_submitplan()
   {
	 var cform = document.cform;
	 var nweek=cform.week.value;
	 cform.summaryflag.value='A';
	 if(isEmpty(nweek) || nweek == -1 )
	   {
		 alert("<%=message.getMessageDesc("PLEASE_SELECT")%>");
	     return;
	  }
    if ( ! confirm("<%= message.getMessageDesc("ARE_YOU_SURE_SUBMIT") %>") )  return;
  	document.cform.actionname.value = "submitplan";
  	document.cform.target = "_parent";
  	isRunning = true;
  	document.cform.submit();
  }
</script>	
</head>

<body>
	<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_visitplaneditsummary">
    <input type="hidden" name="actionname">
    <custom:hidden property="contactid"/>
    <custom:hidden property="orgid"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="summaryflag"/>	
    	<input type="hidden" name="week"/>
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
   	<%
   	Integer oYear=(Integer)pageContext.getAttribute("year");
   	Integer oMonth=(Integer)pageContext.getAttribute("monthofyear");
   	String strIsHistory=(String)pageContext.getAttribute("ishistory");
   	boolean isHistory="Y".equals(strIsHistory);
   	Calendar cal=Calendar.getInstance();
		cal.set(Calendar.YEAR,oYear.intValue());
		cal.set(Calendar.MONTH,oMonth.intValue()-1);
		cal.set(Calendar.DATE,1);
		cal.setFirstDayOfWeek(Calendar.MONDAY);
		int theFirstDayOfWeek=cal.get(Calendar.DAY_OF_WEEK)-1;
		if (0 == theFirstDayOfWeek) {  
			theFirstDayOfWeek = 7;  
	    }  
		int theLastDayOfMonth=cal.getActualMaximum(Calendar.DAY_OF_MONTH );
		int theLastWeekOfMonth=cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
		java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(label.getLabelName("L_YearAndMonthFormat"));
		String strYearAndMonth=sdf.format(cal.getTime());
   	%>
   	<tr><td class="summary_top"></td></tr>
   		<tr><td class="summary_top"></td></tr>
   <tr>
		<td class="title_center"><B><u><%=label.getLabelName("L_VisitActivity")%>[<%=strYearAndMonth%>]</u></B></td>
	</tr>	
	<tr><td class="summary_top"></td></tr>
	<tr>
		<td>
		 <div style="overflow:auto;height:280">
			<table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellpadding="0" width="100%">

        <tr class="deepblue-left">
          <td width="2%" class="title_center">&nbsp;</td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Monday")%></td>
          <td class="title_center"><%=label.getLabelName("L_Tuesday")%></td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Wednesday")%></td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Thursday")%></td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Friday")%></td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Saturday")%></td>
          <td width="14%" class="title_center"><%=label.getLabelName("L_Sunday")%></td>
         </tr>
         <%
         Vector vDetails=(Vector)pageContext.getAttribute("visitplandetails");
         if(vDetails==null)
         	vDetails=new Vector();
         HashMap oneDetail=null;
         int numCurr=0;
         if(vDetails.size()>numCurr)
         	oneDetail=(HashMap)vDetails.get(numCurr);
         int firstWeek=0;
         int firstDayOfWeek=0;
         if(oneDetail!=null)
         {
         	if(oneDetail.containsKey("weekofmonth"))
         		firstWeek=((Integer)oneDetail.get("weekofmonth")).intValue();
         	if(oneDetail.containsKey("dayofweek"))
         		firstDayOfWeek=((Integer)oneDetail.get("dayofweek")).intValue();
         	
         }	
         String strTRClass="td-listrom";
         int nDay=0;
         for(int i=1;i<=theLastWeekOfMonth;i++)
         {
         %>
         
         	<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='none'"  onClick="javascript:page_selectedweek('<custom:write property="year"/>','<custom:write property="monthofyear"/>','<%=i%>');" > 
         		
            <td height="22">
              <input type="radio" id="rdo_week<%=i%>" name="checkweekradio" value="<%=i%>" class="normalradio">
            </td>
            <%
            
            for(int j=1;j<=7;j++)
            {
            	
              
            	if((i==1 && j<theFirstDayOfWeek ) || (i>1 && nDay>=theLastDayOfMonth)){
            %>
            	<td class="disabled_day">&nbsp;</td>
            	<%}else 
            		{
            		nDay++;
            		if(vDetails.size()<=numCurr ){
            		%>
            	<td onMouseOver="this.className='current_day';" onMouseOut="this.className='none';span_day_<%=nDay%>.style.display='none';" onClick="javascript:page_selectedday('<custom:write property="year"/>','<custom:write property="monthofyear"/>','<%=i%>','<%=j%>','<%=nDay%>');"><span id="span_day_<%=nDay%>" style="display:none"><%=nDay%></span>&nbsp;
            	<%out.println(nDay);%>
            	</td>
            	<%}else if(oneDetail!=null && (i>firstWeek  || (i==firstWeek && j>=firstDayOfWeek))){
            		%>
            	
            		<%
            		
            		int nCurrWeek=((Integer)oneDetail.get("weekofmonth")).intValue();
            		int nCurrDayOfWeek=((Integer)oneDetail.get("dayofweek")).intValue();
            		if(i==nCurrWeek && j==nCurrDayOfWeek)
            		{
            		%>
            		<td onMouseOver="this.className='current_day';" onMouseOut="this.className='none';span_day_<%=nDay%>.style.display='none';" onClick="javascript:page_selectedday('<custom:write property="year"/>','<custom:write property="monthofyear"/>','<%=i%>','<%=j%>','<%=nDay%>');"><span id="span_day_<%=nDay%>" style="display:none"><%=nDay%></span>&nbsp;
            		<%out.println(nDay);%>
            		<table width="100%" border="0" cellspacing="0" cellpadding="0">
            			<%
            			
            		int rownum = 0;
            		String strCustomerName="";
            		Integer oActivityType=null;
            		while(i==nCurrWeek && j==nCurrDayOfWeek)
            		{
            			oActivityType=(Integer)oneDetail.get("activitytype");
            			strCustomerName=(String)oneDetail.get("customername");
            			rownum ++;
            		%>
            		<tr>
            			<td class="title_center">&nbsp;
            				<%if(oActivityType.intValue()==1){
            					out.println(rownum);out.println(".");out.println(strCustomerName);
            				}else{
            					pageContext.setAttribute("activitytype",oActivityType);
            					pageContext.setAttribute("displayflag","view");
            				%>
            				<% out.println(rownum);out.println(".");%>(<custom:selectdic property="activitytype" dictType="ZVisitProcessType"  />)
           		
            				<%
            				pageContext.removeAttribute("displayflag");
            			}%>
            			</td>
            		<%
            			numCurr++;
            			if(vDetails.size()>numCurr)
            			{
            				oneDetail=(HashMap)vDetails.get(numCurr);
            			}
            			else
            				break;
            		  nCurrWeek=((Integer)oneDetail.get("weekofmonth")).intValue();
            		  nCurrDayOfWeek=((Integer)oneDetail.get("dayofweek")).intValue();
            		%>
            	</tr>
            			
            		<%}
            		%>
            </table>
            </td>
            
            	<%}else{
            		%>
            	<td onMouseOver="this.className='current_day';" onMouseOut="this.className='none';span_day_<%=nDay%>.style.display='none';" onClick="javascript:page_selectedday('<custom:write property="year"/>','<custom:write property="monthofyear"/>','<%=i%>','<%=j%>','<%=nDay%>');"><span id="span_day_<%=nDay%>" style="display:none"><%=nDay%></span>&nbsp;
            	<%out.println(nDay);%>
            	</td>
            	
            <%}
            }
          else{
          	%>
          	<td onMouseOver="this.className='current_day';" onMouseOut="this.className='none';span_day_<%=nDay%>.style.display='none';" onClick="javascript:page_selectedday('<custom:write property="year"/>','<custom:write property="monthofyear"/>','<%=i%>','<%=j%>','<%=nDay%>');"><span id="span_day_<%=nDay%>" style="display:none"><%=nDay%></span>&nbsp;
          	<%out.println(nDay);%></td>
            	
          	<%
          		}
            }
            }%>
            
          </tr>  
          <%}%>
        </table>
		</td>
	 </tr>	
   </table>
   			   </div> 	 
    <table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
              <!-- 
             <a onclick="page_addfromtemplet();"><custom:button type="1" label="L_AddFromTemplet" imgsrc="new.gif" border="0" style="width:130"/></a>
              -->
             	<a onclick="page_submitplan()"><custom:button type="1" label="L_SubmitWeekPlan" imgsrc="submit_batch.gif" border="0" style="width:80"/></a>
             	<a onclick="page_editweek();"><custom:button type="1" label="L_EditWeekVisitPlan" imgsrc="new.gif" border="0" style="width:100"/></a>
             	<!-- <a onclick="page_back();"><custom:button type="1" label="L_Back" imgsrc="back.gif" border="0" style="width:60"/></a> -->	
            </td>
          </tr>
        </table>  	
  </form>  
</body>

</html>



